﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace testy {
	/// <summary>
	/// klasa pytania z pamiętanymi odpowiedziami użytkownika
	/// </summary>
	public class CheckedQuestion : Question {
		private new List<CheckedAnswer> answers;
		public CheckedQuestion(Question q, List<CheckedAnswer> a) {
			this.content = q.Content;
			this.everyProper = q.EveryProper;
			this.checkedCount = q.CheckedCount;
			this.answers = a;
		}
		public bool IsValidAnswer {
			get {
				int maxCounter;
				if(checkedCount > 0) {
					maxCounter = this.checkedCount;
				} else {
					maxCounter = this.answers.Count;
				}
				int i = 0;
				while(i < maxCounter) {
					if(this.answers[i].IsChecked == this.answers[i].IsProper) {
						i++;
					} else  {
						return false;
					}
				}
				return true;
			}
		}
		public double Points() {
			double p = 0;
			if(!(this.everyProper && this.IsValidAnswer)) {
				return p;
			}
			for(int i=0; i<answers.Count; i++) {
				p+=answers[i].Pt;
			}
			return p;
		}
		public new List<CheckedAnswer> Answers {
			get { return this.answers; }
		}
		public double MaxPoints {
			get { 
				double sum = 0;
				for(int i=0; i<this.answers.Count; i++) {
					if(this.answers[i].IsProper) {
						sum += this.answers[i].Points;
					}
				}
				return sum;
			}
		}
	}
}
